<?php
    use app\modules\cn\models\RankingAll;
    use app\modules\cn\models\ExerciseList;
    use app\modules\cn\models\ExerciseListDetail;
    $model = new ExerciseList();
    $userId = Yii::$app->session->get('userId');
?>
<link rel="stylesheet" href="/cn/css/exerciseNew/speakIndex.css?v=1.1">
<script src="https://file.viplgw.cn/ui/public/lib/vue/vue.js"></script>

<section id="readIndex">
    <div class="readIndexCover">
        <p class="title"><a href="/cn/exercise/practice">做题练习</a> > <span>口语练习</span></p>

        <div class="readIndexContent">
            <div class="contentLeft">
                <!--      一级分类          -->
                <div class="oneLevel">
                    <a href="" class="onelevelitem on">全部剑雅</a>
                    <!-- <a href="" class="onelevelitem">按题型练</a>
                    <a href="" class="onelevelitem">按话题练</a>
                    <a href="" class="onelevelitem">按难度练</a> -->
                </div>
                <!--      二级分类          -->
                <div class="twoLevel">
                    <?php if ($datelist): ?>
                        <?php foreach ($datelist as $key => $value): ?>
                            <a href="/cn/exercise/speak?category=all&cate_id=<?php echo $value['cate_id']?>" class="twolevelitem <?php echo $cate_id==$value['cate_id']?'on':''?>"><?php echo $value['name']?></a>
                        <?php endforeach ?>
                    <?php endif ?>
                    <!-- <a href="" class="twolevelitem on">剑雅12</a>
                    <a href="" class="twolevelitem">剑雅12</a>
                    <a href="" class="twolevelitem">剑雅12</a>
                    <a href="" class="twolevelitem">剑雅12</a> -->
                </div>
                <?php foreach ($list as $key => $value): ?>
                    <p class="typeTitle"><?php echo $key?></p>
                    <div class="readList">
                        <!-- 未做 noDo  已做 isDo -->
                        <?php foreach ($value as $k => $v): ?>
                            <?php 
                                // $model=new content();
                                $pid = $v['content_id'];
                                $resultid = RankingAll::find('resultid')->where(['userid' =>$userId,'typeid' =>4,'pid' =>$pid])->andWhere(['not', ['testid' => null]])->orderBy('id desc')->distinct()->asArray()->One();
                                // f_d($resultid);
                                $resultid = $resultid['resultid'];
                                // f_d($resultid['resultid']);
                                $name = $v['name'];
                                // 查看是否做过题
                                $isDo= RankingAll::find()->select(['pid'])->where(['userid' =>$userId,'typeid'=>4,'pid'=>$pid])->andWhere(['not', ['newid' => null]])->distinct()->asArray()->All();
                                // f_d($isDo);
                                // 查询有多少人做过这道题
                                $isDoPeople= count(RankingAll::find()->select(['pid'])->where(['typeid'=>4,'pid'=>$pid])->andWhere(['not', ['newid' => null]])->distinct()->asArray()->All());

                                $dal = $model->getlistenexercisedotest($pid);
                                // f_d($dal);
                                $allnumber = 0; // 所有做过题数
                                $allnum = 0; // 所有题数
                                $alltruenumber = 0; // 所有正确题数
                                // $num = 0;
                                foreach ($dal as $vcc)
                                {
                                    // $vount = $vount + $vcc['viewCount'];
                                    $id = $vcc['content_id'];
                                    // 总数
                                    $num = count(ExerciseListDetail::find()->where(['pid' =>$id])->asArray()->All()); 
                                    $allnum = $allnum + $num;
                                    // 做题数
                                    $number = count(RankingAll::find()->where(['userid' =>$userId,'typeid' =>4,'pid' =>$id, 'resultid'=>$resultid])->andWhere(['not', ['testid' => null]])->asArray()->All()); 
                                    $allnumber = $allnumber + $number;
                                    // 正确
                                    $truenumber = count(RankingAll::find()->where(['userid' =>$userId,'result'=>1,'typeid' =>1,'pid' =>$id])->andWhere(['not', ['testid' => null]])->asArray()->All()); 
                                    $alltruenumber = $alltruenumber + $truenumber;
                                }

                                // var_dump($allnumber,$allnum);die();
                            ?>

                            <div class="readTypeItem ">
                                <div class="goCover"><a href="/cn/exercise/speak-detail?content_id=<?php echo $v['content_id']?>" class="goBtn">去练习</a></div>
                                <div class="<?php echo !empty($isDo) ? 'isDo' : 'noDo'?>"><?php echo !empty($isDo) ? '已做' : '未做'?></div>
                                <div class="itemImg">
                                    <img src="<?php echo $v['title_image']?$v['title_image']:''?>" alt="">
                                    <p class="itemSec"><?php echo $v['part_name']?></p>
                                </div>
                                <div class="updateCover">
                                    <div class="peopleNum">
                                        <p>已有<?php echo $v['viewCount']+$isDoPeople?>人参加练习</p>
                                        <span>一周前更新题库</span>
                                    </div>
                                    <div class="topicJd"><?php echo $allnumber?>/<?php echo $allnum?></div>
                                </div>
                            </div>
                        <?php endforeach ?>
                    </div>
                <?php endforeach ?>
            </div>

            <div class="contentRight">
                <p class="rightTitle">最新优惠活动</p>
                <div class="rightImg">
                    <a href="https://p.qiao.baidu.com/cps/chat?siteId=16998561&userId=33849315&siteToken=0848542c0e71b685b68768fcec8e99ef">
                        <img src="/cn/images/exerciseNew/youhui1.png" alt="">
                    </a>
                </div>
                <?php if ($banner&&$banner['image2']): ?>
                    <div class="rightImg">
                        <a href="<?php echo $banner['image_url2']?$banner['image_url2']:''?>">
                            <img src="<?php echo $banner['image2']?$banner['image2']:''?>" alt="">
                        </a>
                    </div>
                <?php endif ?>
                
            </div>
        </div>
    </div>
</section>


<script src="/cn/js/exerciseNew/speakIndex.js?v=1.1"></script>